home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5546 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  67 lines

  1. Path: cypher.3do.com!user
  2. From: tsw@3do.com (Tom Watson)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Where Can I Find Standard C Library Sourc
  5. Date: Thu, 08 Feb 1996 11:26:44 -0800
  6. Organization: The 3DO Corporation
  7. Distribution: world
  8. Message-ID: <tsw-0802961126440001@cypher.3do.com>
  9. References: <4f8915$jt@mother.usf.edu> <4fb8mf$ouo@spanky.pls.ov.com>
  10. NNTP-Posting-Host: cypher.3do.com
  11.  
  12. In article <4fb8mf$ouo@spanky.pls.ov.com>, glenn@ov.com wrote:
  13.  
  14. > In article jt@mother.usf.edu, yatesc@csee.usf.edu (Randy Yates) writes:
  15. > >I mean the source for functions like printf and strcpy.
  16. > >
  17. > >I've read the FAQ but didn't see anything about this.
  18. <<<<<Deletia>>>
  19. > printf is usually very system specific once you get down to the level
  20. > of actually outputting characters to a display device.  Therefore,
  21. > you can only talk about source for a specific platform.
  22. > As for strcpy:
  23. > int strcpy(char *destination, char *source)
  24. > {
  25. >      while((*destination++ = *source++) != '\0');
  26. > }
  27.  
  28. One should read something about the return value for 'strcpy'.  A more
  29. 'correct' version of this is something like:
  30.  
  31. char *strcpy (char *destination, const char *source)
  32.    {
  33.    char *ret = destination;
  34.    while ((*destination++ = *source++) != '\0')
  35.       ;
  36.    return ret;
  37.    }
  38.  
  39. The other forms of the while statement (or other looping structure used in
  40. its place) are left as an excercise of the reader.  There are several
  41. forms that it can take, and most of them will have the desired result.  If
  42. the compiler is good, they all will be efficient.  Inclusion of "Duff's
  43. device" is also left as an excercise for the reader.
  44.  
  45. > In general, it depends on the purpose of the function as to how
  46. > platform independent the source is.  Usually anything that uses
  47. > system hardware (I/O devices, Floating Point Units, etc) is
  48. > system dependent, and just about everything else is not.
  49. >                 Fletcher.Glenn@ov.com
  50.  
  51. A "really good source" of library routines for C is Plauger's book (_The
  52. Standard C Library_) which is VERY good at explaining the library, AND how
  53. to use it.  The portion of the standard relating to the library routines
  54. is also included, and is VERY helpful in the explainations as well.  All
  55. in all a VERY recommended book.  
  56.  
  57. P.S.  It has the source as well, and is pretty much system independent.
  58.  
  59. -- 
  60. Tom Watson
  61. tsw@3do.com         (Home: tsw@johana.com)
  62.